package com.wnxy.provider.controller;


import com.wnxy.common.model.Student;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Doctor
 * @date 2025-03-21
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("/stu")
public class StudentController {

    @Value("${server.port}")
    private int port;
    @GetMapping("/{id}")
    public Student getStudentById(@PathVariable("id") int id) {
        System.out.println("我是服务提供者...");
        Student student = new Student();
        student.setName("张三"+port);
        student.setAge(10 + id);
        if (id > 20){
            student.setName("我是异常处理...");
        }
        return student;
    }

    @PostMapping
    public void saveStudent(@RequestBody Student student) {

        Student s = new Student();
        s.setName(student.getName());
        s.setAge(student.getAge());

        System.out.println("name:" + s.getName());
        System.out.println("Age:" + s.getAge());

    }

    @PutMapping
    public void updateStudent(@RequestBody Student student) {
        Student s = new Student();

        s.setId(1);
        s.setName("shuai");
        s.setAge(20);

        System.out.println(s.getId());
        System.out.println(s.getName());
        System.out.println(s.getAge());

        if (s.getId().equals(student.getId())) {
            s.setName(student.getName());
            s.setAge(student.getAge());
            System.out.println(s.getName());
            System.out.println(s.getAge());
        }else{
            System.out.println("查无此人");
        }

    }


}
